{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fa1057ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[8, 2, 2, 1, 8],\n",
       "       [3, 9, 3, 0, 3],\n",
       "       [4, 6, 1, 7, 6],\n",
       "       [1, 9, 2, 7, 4]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# np.random.randint(50,100,(20,5))\n",
    "# np.array([[random.randint(0,100) for i in range(9)] for j in range(20)])\n",
    "# np.random.randn 生成的数据有负数\n",
    "# np.random.randint 生成的数据只有正数\n",
    "\n",
    "\n",
    "arr = np.random.randint(0,10,(4,5))\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6c1fc126",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 9,  3,  3,  2,  9],\n",
       "       [ 4, 10,  4,  1,  4],\n",
       "       [ 5,  7,  2,  8,  7],\n",
       "       [ 2, 10,  3,  8,  5]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f0ceed5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 7,  1,  1,  0,  7],\n",
       "       [ 2,  8,  2, -1,  2],\n",
       "       [ 3,  5,  0,  6,  5],\n",
       "       [ 0,  8,  1,  6,  3]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0cd4088b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4. , 1. , 1. , 0.5, 4. ],\n",
       "       [1.5, 4.5, 1.5, 0. , 1.5],\n",
       "       [2. , 3. , 0.5, 3.5, 3. ],\n",
       "       [0.5, 4.5, 1. , 3.5, 2. ]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a1bd63d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[16,  4,  4,  2, 16],\n",
       "       [ 6, 18,  6,  0,  6],\n",
       "       [ 8, 12,  2, 14, 12],\n",
       "       [ 2, 18,  4, 14,  8]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f11351cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([48, 30, 92, 18, 25, 48,  8, 92,  4])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "newArr = np.array([random.randint(0,100) for i in range(9)])\n",
    "newArr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "cf47c396",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([49, 31, 93, 19, 26, 49,  9, 93,  5])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "newArr + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b65917ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([47, 29, 91, 17, 24, 47,  7, 91,  3])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "newArr - 1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a42551c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([24. , 15. , 46. ,  9. , 12.5, 24. ,  4. , 46. ,  2. ])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "newArr / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "5a1283c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 96,  60, 184,  36,  50,  96,  16, 184,   8])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "newArr * 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "230af3aa",
   "metadata": {},
   "source": [
    "# 区别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "717e9429",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1,2,3,4,5]\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f779a051",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate list (not \"int\") to list",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[28], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m a \u001B[38;5;241m+\u001B[39m \u001B[38;5;241m1\u001B[39m\n",
      "\u001B[1;31mTypeError\u001B[0m: can only concatenate list (not \"int\") to list"
     ]
    }
   ],
   "source": [
    "a + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "cf4a343b",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for -: 'list' and 'int'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[29], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m a \u001B[38;5;241m-\u001B[39m \u001B[38;5;241m1\u001B[39m\n",
      "\u001B[1;31mTypeError\u001B[0m: unsupported operand type(s) for -: 'list' and 'int'"
     ]
    }
   ],
   "source": [
    "a - 1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2c1a68e9",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'list' and 'int'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[30], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m a \u001B[38;5;241m/\u001B[39m \u001B[38;5;241m2\u001B[39m\n",
      "\u001B[1;31mTypeError\u001B[0m: unsupported operand type(s) for /: 'list' and 'int'"
     ]
    }
   ],
   "source": [
    "a / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "90284f9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a * 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40f9cf27",
   "metadata": {},
   "source": [
    "# 数组间计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "ac92b2bc",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "operands could not be broadcast together with shapes (4,5) (9,) ",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[32], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m arr \u001B[38;5;241m+\u001B[39m newArr\n",
      "\u001B[1;31mValueError\u001B[0m: operands could not be broadcast together with shapes (4,5) (9,) "
     ]
    }
   ],
   "source": [
    "arr + newArr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "599b5fdf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
